package ar.edu.unq.svnpermission.ui.pages;



import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.repeater.RepeatingView;

import ar.edu.unq.svnpermission.ui.model.UseCase;

public abstract class InternalPage<E  extends UseCase> extends PageTemplate<E> {
	private static final long serialVersionUID = 1L;
	
	public InternalPage()
	{
		super();
		this.addMenu();
	}
	
	public void addMenu()
	{
		RepeatingView rv = new RepeatingView("menu");	
		this.add(rv);		

		this.createNewUserItem(rv);
		this.createPermissionManagerMenuitem(rv);
		this.createNewGroupItem(rv);
		this.createGroupsItem(rv);
		this.createNewFolderItem(rv);
		this.createUsersItem(rv);
		
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void createMenuItem(String label, Class pageClass, RepeatingView rv,String iconName)
	{
		WebMarkupContainer parent = new WebMarkupContainer(rv.newChildId());
		rv.add(parent);		
		Image itemImage = new Image("iconImage","images/" + iconName + ".png"){
			
		};		
		itemImage.add(new SimpleAttributeModifier("src", "http://localhost:8080/SvnPermissionAdmin.Web.UI/images/" + iconName + ".png"));
		BookmarkablePageLink link =  new BookmarkablePageLink("menuLink",pageClass);
		link.add(new Label("menuCaption",label));
		link.add(itemImage);
		parent.add(link);

	}
	
	private void createNewUserItem(RepeatingView rv)
	{
		this.createMenuItem("Nuevo Usuario", NewUserPage.class,rv,"newuser");
	}	
		
	private void createPermissionManagerMenuitem(RepeatingView rv)
	{
		this.createMenuItem("Carpetas y Permisos", PermissionManagerPage.class,rv,"permissions");
	}	
	
	private void createNewGroupItem(RepeatingView rv)
	{
		this.createMenuItem("Nuevo Grupo", NewGroupPage.class,rv,"newgroup");
	}
	
	private void createGroupsItem(RepeatingView rv)
	{
		this.createMenuItem("Grupos", GroupsPage.class,rv, "groups");
	}	
	
	private void createNewFolderItem(RepeatingView rv)
	{
		this.createMenuItem("Nueva Carpeta", NewFolderPage.class,rv,"newfolder");
	}
	
	private void createUsersItem(RepeatingView rv)
	{
		this.createMenuItem("Usuarios", UsersPage.class,rv,"users");
	}	
	
}
